<template>
  <div class="quick-apply-Wrap">
    <div class="quick-apply-search">
      <span class="page-title">快速求职列表</span>
      <el-input placeholder="请输入搜索内容" v-model="keyWords" class="input-with-select search-keyword">
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="联系电话" value="1"></el-option>
        </el-select>
      </el-input>
      <el-button type="primary" size="small" icon="el-icon-search" @click="searchQuickApply">搜索</el-button>
      <el-button type="info" size="small" class="search-keyword-reset" plain @click="resetSearch">重置</el-button>
    </div>

    <div class="quick-apply-table">
      <el-table ref="multipleTable" :data="quickApplyData" border stripe fit v-loading="listLoading"
                :row-style="{height:'50px'}" :header-row-style="{height:'40px'}" @filter-change="filterChange">
        <el-table-column label="id" width="80">
          <template slot-scope="scope">
            {{scope.row.id}}
          </template>
        </el-table-column>
        <el-table-column label="联系电话" width="110">
          <template slot-scope="scope">
            {{scope.row.phone}}
          </template>
        </el-table-column>
        <el-table-column label="求职地址" width="240" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.workAddress}}
          </template>
        </el-table-column>
        <el-table-column label="期望职位" width="180">
          <template slot-scope="scope">
            {{scope.row.workPost}}
          </template>
        </el-table-column>
        <el-table-column label="工资要求" width="160">
          <template slot-scope="scope">
            {{scope.row.workWage}}
          </template>
        </el-table-column>
        <el-table-column label="年龄" width="80">
          <template slot-scope="scope">
            {{scope.row.age}}
          </template>
        </el-table-column>
        <el-table-column label="性别" width="80">
          <template slot-scope="scope">
            {{scope.row.sex | changeSex}}
          </template>
        </el-table-column>
        <el-table-column label="客服是否处理" width="130"
                         :filters="[{ text: '未处理', value: 0 }, { text: '已处理', value: 1 }]"
                         :filter-multiple="false" column-key="status"
                         filter-placement="bottom-end">
          <template slot-scope="scope">
            {{scope.row.status | changeType}}
          </template>
        </el-table-column>
        <el-table-column label="是否删除" width="80">
          <template slot-scope="scope">
            {{scope.row.delStatus | changeDelete}}
          </template>
        </el-table-column>
        <el-table-column label="生成时间" width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.time">{{scope.row.time | formatTime}}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" min-width="200" fixed="right">
          <template slot-scope="{row}">
            <el-dropdown size="mini" :split-button="true" type="primary" @click="handleLook(row)"
                         v-if="checkPermissionPoints(3) == 1">查看
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(row)" v-if="checkPermissionPoints(4) == 1">编辑
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :type="1" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                  @pagination="getQuickApplyList"/>
    </div>


    <!--查看-->
    <el-dialog title="详细信息" :visible.sync="dialogLookVisible" width="960px" class="quick-apply-dialog look-dialog"
               top="11vh">
      <el-form label-width="140px" size="small">
        <el-form-item label="id：">
          <span>{{quickApply.id}}</span>
        </el-form-item>
        <el-form-item label="联系电话：">
          <span>{{quickApply.phone}}</span>
        </el-form-item>
        <el-form-item label="求职地址：">
          <span>{{quickApply.workAddress}}</span>
        </el-form-item>
        <el-form-item label="期望职位：">
          <span>{{quickApply.workPost}}</span>
        </el-form-item>
        <el-form-item label="工资要求：">
          <span>{{quickApply.workWage}}</span>
        </el-form-item>
        <el-form-item label="年龄：">
          <span>{{quickApply.age}}</span>
        </el-form-item>
        <el-form-item label="性别：">
          <span>{{quickApply.sex | changeSex}}</span>
        </el-form-item>
        <el-form-item label="客服处理状态：">
          <span>{{quickApply.status | changeType}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" style="width: 96px" @click="dialogLookVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <!--编辑-->
    <el-dialog title="编辑" :lock-scroll="true" :visible.sync="dialogEditVisible" width="960px" top="11vh"
               class="quick-apply-dialog">
      <el-form :model="ruleForm" ref="ruleForm" :rules="rules" label-width="auto" size="mini">
        <el-form-item label="id：">
          <span>{{ruleForm.id}}</span>
        </el-form-item>
        <el-form-item label="联系电话：">
          <span>{{ruleForm.phone}}</span>
        </el-form-item>
        <el-form-item label="求职地址：">
          <span>{{ruleForm.workAddress}}</span>
        </el-form-item>
        <el-form-item label="期望职位：">
          <span>{{ruleForm.workPost}}</span>
        </el-form-item>
        <el-form-item label="工资要求：">
          <span>{{ruleForm.workWage}}</span>
        </el-form-item>
        <el-form-item label="年龄：">
          <span>{{ruleForm.age}}</span>
        </el-form-item>
        <el-form-item label="性别：">
          <span>{{ruleForm.sex | changeSex}}</span>
        </el-form-item>
        <el-form-item label="客服处理状态：" prop="status">
          <el-radio-group v-model="ruleForm.status">
            <el-radio :label=0>未处理</el-radio>
            <el-radio :label=1>已处理</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="success" style="width: 96px" @click="saveQuickApply" :loading="sendLoad">保存
        </el-button>
        <el-button size="small" style="width: 96px" @click="dialogEditVisible = false">取消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import Pagination from '@/components/Pagination';
  import {mapGetters} from 'vuex';
  import {permissionPoints} from '@/utils/permission';
  import {baseUrl} from "@/api/constant";
  import {formatDate} from "@/utils/index";
  import {addQuickApply, getInitQuickApplyList, getQuickApplyDetail} from "../../../api/service/service";

  export default {
    name: "quickApplyJob",
    computed: {
      ...mapGetters([
        'points'
      ])
    },
    components: {
      Pagination
    },
    data() {
      return {
        total: 0,
        listQuery: {
          page: 1,
          limit: 20,
          phone: '',
          status: ''
        },
        keyWords: '',
        select: '1',
        listLoading: false,
        dialogLookVisible: false,
        dialogEditVisible: false,
        quickApplyData: [],
        quickApply: {},
        ruleForm: {
          id: '',
          phone: '',
          workAddress: '',
          workPost: '',
          workWage: '',
          age: '',
          sex: '',
          status: ''
        },
        rules: {
          status: [
            {required: true, message: '请选择客服处理状态', trigger: 'change'}
          ]
        },
        sendLoad: false
      }
    },
    created() {
      this.getQuickApplyList();
    },
    methods: {
      searchQuickApply() {
        if (this.keyWords == '' || this.keyWords == undefined) {
          return this.$message.info({message: '请输入搜索内容', duration: 1000});
        }
        if (this.select == 1) {
          this.listQuery.phone = this.keyWords;
        }
        this.listQuery.page = 1;
        this.getQuickApplyList();
      },
      resetSearch() {
        this.select = '1';
        this.keyWords = '';
        this.listQuery.phone = '';
        this.listQuery.status = '';
        this.$refs.multipleTable.clearFilter();
        this.listQuery.page = 1;
        this.getQuickApplyList();
      },
      filterChange(value) {//过滤
        this.listQuery.status = String(value.status);
        this.listQuery.page = 1;
        this.getQuickApplyList();
      },
      getQuickApplyList() {
        this.listLoading = true;
        getInitQuickApplyList(this.listQuery).then((res) => {
          this.listLoading = false;
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            const {items, totalRecord} = retObj.data;
            this.total = totalRecord;
            this.quickApplyData = items;
          }
        }).catch(() => {
          this.listLoading = false;
        })
      },
      checkPermissionPoints(type) {
        let pointObj = this.points.quickApplyJob;
        return permissionPoints(type, pointObj);
      },
      saveQuickApply() {
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            this.sendLoad = true;
            addQuickApply({
              'id': this.ruleForm.id,
              'status': this.ruleForm.status
            }).then((res) => {
              let retObj = res;
              this.sendLoad = false;
              if (retObj.code == 0 && retObj.data == 1) {
                this.dialogEditVisible = false;
                this.$refs.ruleForm.resetFields();
                this.$message.success({message: '修改成功', duration: 2000});
                this.getQuickApplyList();
              } else {
                this.$message.error({message: '修改失败，请重试', duration: 2000});
              }
            }).catch(() => {
              this.sendLoad = false;
            })
          }
        })
      },
      handleLook(row) {
        this.dialogLookVisible = true;
        getQuickApplyDetail(row.id).then((res) => {
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            this.quickApply = retObj.data;
          }
        })
      },
      handleEdit(row) {
        this.dialogEditVisible = true;
        getQuickApplyDetail(row.id).then((res) => {
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            this.ruleForm = retObj.data;
          }
        })
      }
    },
    filters: {
      formatTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
      },
      changeType(type) {
        if (type == 0) {
          return '未处理';
        } else {
          return '已处理';
        }
      },
      changeSex(type) {
        if (type == 0) {
          return '未知';
        } else if (type == 1) {
          return '男';
        } else if (type == 2) {
          return '女';
        }
      },
      changeDelete(type) {
        if (type == 0) {
          return '否';
        } else if (type == 1) {
          return '是';
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .quick-apply-Wrap {
    .quick-apply-search {
      display: flex;
      align-items: center;
      width: 100%;
      height: 80px;
      .page-title {
        padding-left: 18px;
        min-width: 160px;
        text-align: left;
        font-size: 18px;
        font-weight: bold;
        color: rgba(61, 68, 77, 1);
      }
      .search-keyword {
        margin-right: 24px;
        width: 470px;
        > > > .el-select .el-input {
          width: 110px;
        }
        > > > .el-input-group__prepend {
          background-color: #fff;
        }
      }
      .search-keyword-reset {
        margin-right: 36px;
      }
    }

    .quick-apply-table {
      width: 98%;
      margin-left: 18px;
      > > > .el-table td, .el-table th {
        padding: 6px 0px;
      }
      > > > .el-table__header th {
        padding: 0;
        height: 30px;
        line-height: 30px;
      }
      > > > .el-table__fixed-right {
        height: 100% !important;
      }
      > > > .el-table__column-filter-trigger {
        line-height: 28px;
        i {
          font-size: 18px;
        }
      }
      > > > .el-table__row .cell {
        display: flex;
        align-items: center;
      }
      > > > .el-table__header .has-gutter .cell {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .quick-apply-dialog > > > .el-dialog .el-dialog__header {
      display: flex;
      align-items: center;
      height: 48px;
      background: #F7F8FA;
      padding: 0px 0px 0px 12px;
      .el-dialog__headerbtn {
        top: 15px;
      }
    }
    .look-dialog > > > .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
      margin-bottom: 0px;
    }
    .quick-apply-dialog {
      font-size: 14px;
      color: #606266;
    }

    > > > .el-button {
      line-height: 1.2;
    }
  }
</style>
